package com.neusoft.neuhealth.service;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.StringRedisTemplate;
import org.springframework.stereotype.Service;

import java.util.concurrent.TimeUnit;

@Service
public class RedisService {
    @Autowired
    private StringRedisTemplate redisTemplate;

    // 存储token
    public void setToken(String username, String token, long expireTime) {
        redisTemplate.opsForValue().set(username, token, expireTime, TimeUnit.SECONDS);
    }

    // 获取token
    public String getToken(String username) {
        return redisTemplate.opsForValue().get(username);
    }

    // 删除token
    public void deleteToken(String username) {
        redisTemplate.delete(username);
    }

    // 检查token是否存在
    public boolean hasToken(String username) {
        return redisTemplate.hasKey(username);
    }
}
